<?php
//error_reporting(E_ERROR|E_PARSE);
header("Content-Type:text/html; charset=utf-8");
session_start();
if($_SESSION["islogin"]!=='igiveyouthepower'){
echo "<script language=JavaScript>\r\n";
echo "alert('请先登录');\r\n";
echo "location.href='../index.php'\r\n";
echo "</script>";
}else{
require_once('../config.php');
$conn = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);
mysql_select_db($cfg_dbname,$conn);
function export_xls($filename,$table){
    $exportString=$table;
 
    header("Cache-Control:public");
    header("Pragma:public");
    header("Content-type: Content-type:application/vnd.ms-excel");
    header("Accept-Ranges: bytes");
    header("Content-Disposition:attachment; filename=".$filename);
    header("Content-length:".strlen($exportString));
    echo $exportString;
    exit;
}
$lang=$_GET["lang"];
$bname=$_GET["bname"];
$user_name=$_SESSION["managername"];
if($_SESSION["thetype"]=="管理员"){$sql="select * from ph_".$lang." where 1=1";}else{$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
$result=mysql_query($sql);
$tablehead='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" style="font-size:12px">
  <tr height="21">
    <td bgcolor="#FFCC00"><strong>TemplateType=Sports</strong></td>
    <td bgcolor="#FFCC00"><strong>Version=2013.0903</strong></td>
    <td colspan="8" bgcolor="#FFCC00" align="center"><strong>The    top 3 rows are for Amazon.com use only. Do not modify or delete the top 3    rows.</strong></td>
    <td colspan="5" bgcolor="#FF0000" align="center"><strong>Offer - Offer    Information - These attributes are required to make your item buyable for    customers on the site.</strong></td>
    <td colspan="4" bgcolor="#99CCFF" align="center"><strong>Dimension - These    attributes specify the size and weight of a product</strong></td>
    <td colspan="12" bgcolor="#99CC00" align="center"><strong>Discovery - These    attributes have an effect on how customers can find your product on the site    using browse or search</strong></td>
    <td colspan="10" bgcolor="#FFFF00" align="center"><strong>Image - Image    Information - See Image Instructions tab for details.</strong></td>
    <td colspan="4" bgcolor="#FF8080" align="center"><strong>Variation - Populate    these attributes if your product is available in different variations (for    example color or wattage)</strong></td>
    <td colspan="4" bgcolor="#FF9900" align="center"><strong>Ungrouped - These    attributes create rich product listings for your buyers.</strong></td>
  </tr>
  <tr height="21">
    <td height="21" bgcolor="#FFCC00">SKU</td>
    <td bgcolor="#FFCC00">Product ID</td>
    <td bgcolor="#FFCC00">Product ID Type</td>
    <td bgcolor="#FFCC00">Item Title</td>
    <td bgcolor="#FFCC00">Brand Name</td>
    <td bgcolor="#FFCC00">Manufacturer</td>
    <td bgcolor="#FFCC00">Manufacturer Part Number</td>
    <td bgcolor="#FFCC00">Product Description</td>
    <td bgcolor="#FFCC00">Feed Product Type</td>
    <td bgcolor="#FFCC00">Update Delete</td>
    <td bgcolor="#FF0000">Standard Price</td>
    <td bgcolor="#FF0000">Currency</td>
    <td bgcolor="#FF0000">Quantity</td>
    <td bgcolor="#FF0000">Condition Type</td>
    <td bgcolor="#FF0000">Item Condition Note</td>
    <td bgcolor="#99CCFF">Shipping Weight</td>
    <td bgcolor="#99CCFF">Website Shipping Weight Unit Of    Measure</td>
    <td bgcolor="#99CCFF">Item Weight</td>
    <td bgcolor="#99CCFF">Item Weight Unit Of Measure</td>
    <td bgcolor="#99CC00">Key Product Features1</td>
    <td bgcolor="#99CC00">Key Product Features2</td>
    <td bgcolor="#99CC00">Key Product Features3</td>
    <td bgcolor="#99CC00">Key Product Features4</td>
    <td bgcolor="#99CC00">Key Product Features5</td>
    <td bgcolor="#99CC00">Recommended Browse Node1</td>
    <td bgcolor="#99CC00">Recommended Browse Node2</td>
    <td bgcolor="#99CC00">Search Terms1</td>
    <td bgcolor="#99CC00">Search Terms2</td>
    <td bgcolor="#99CC00">Search Terms3</td>
    <td bgcolor="#99CC00">Search Terms4</td>
    <td bgcolor="#99CC00">Search Terms5</td>
    <td bgcolor="#FFFF00">Main Image URL</td>
    <td bgcolor="#FFFF00">Swatch Image Url</td>
    <td bgcolor="#FFFF00">Other Image URL1</td>
    <td bgcolor="#FFFF00">Other Image URL2</td>
    <td bgcolor="#FFFF00">Other Image URL3</td>
    <td bgcolor="#FFFF00">Other Image URL4</td>
    <td bgcolor="#FFFF00">Other Image URL5</td>
    <td bgcolor="#FFFF00">Other Image URL6</td>
    <td bgcolor="#FFFF00">Other Image URL7</td>
    <td bgcolor="#FFFF00">Other Image URL8</td>
    <td bgcolor="#FF8080">Parentage</td>
    <td bgcolor="#FF8080">Parent SKU</td>
    <td bgcolor="#FF8080">Relationship Type</td>
    <td bgcolor="#FF8080">Variation Theme</td>
    <td bgcolor="#FF9900">Color</td>
    <td bgcolor="#FF9900">Color Map</td>
    <td bgcolor="#FF9900">Size</td>
    <td bgcolor="#FF9900">Size Map</td>
  </tr>
  <tr height="21">
    <td height="21" bgcolor="#FFCC00">item_sku</td>
    <td bgcolor="#FFCC00">external_product_id</td>
    <td bgcolor="#FFCC00">external_product_id_type</td>
    <td bgcolor="#FFCC00">item_name</td>
    <td bgcolor="#FFCC00">brand_name</td>
    <td bgcolor="#FFCC00">manufacturer</td>
    <td bgcolor="#FFCC00">part_number</td>
    <td bgcolor="#FFCC00">product_description</td>
    <td bgcolor="#FFCC00">feed_product_type</td>
    <td bgcolor="#FFCC00">update_delete</td>
    <td bgcolor="#FF0000">standard_price</td>
    <td bgcolor="#FF0000">currency</td>
    <td bgcolor="#FF0000">quantity</td>
    <td bgcolor="#FF0000">condition_type</td>
    <td bgcolor="#FF0000">condition_note</td>
    <td bgcolor="#99CCFF">website_shipping_weight</td>
    <td bgcolor="#99CCFF">website_shipping_weight_unit_of_measure</td>
    <td bgcolor="#99CCFF">item_weight</td>
    <td bgcolor="#99CCFF">item_weight_unit_of_measure</td>
    <td bgcolor="#99CC00">bullet_point1</td>
    <td bgcolor="#99CC00">bullet_point2</td>
    <td bgcolor="#99CC00">bullet_point3</td>
    <td bgcolor="#99CC00">bullet_point4</td>
    <td bgcolor="#99CC00">bullet_point5</td>
    <td bgcolor="#99CC00">recommended_browse_nodes1</td>
    <td bgcolor="#99CC00">recommended_browse_nodes2</td>
    <td bgcolor="#99CC00">generic_keywords1</td>
    <td bgcolor="#99CC00">generic_keywords2</td>
    <td bgcolor="#99CC00">generic_keywords3</td>
    <td bgcolor="#99CC00">generic_keywords4</td>
    <td bgcolor="#99CC00">generic_keywords5</td>
    <td bgcolor="#FFFF00">main_image_url</td>
    <td bgcolor="#FFFF00">swatch_image_url</td>
    <td bgcolor="#FFFF00">other_image_url1</td>
    <td bgcolor="#FFFF00">other_image_url2</td>
    <td bgcolor="#FFFF00">other_image_url3</td>
    <td bgcolor="#FFFF00">other_image_url4</td>
    <td bgcolor="#FFFF00">other_image_url5</td>
    <td bgcolor="#FFFF00">other_image_url6</td>
    <td bgcolor="#FFFF00">other_image_url7</td>
    <td bgcolor="#FFFF00">other_image_url8</td>
    <td bgcolor="#FF8080">parent_child</td>
    <td bgcolor="#FF8080">parent_sku</td>
    <td bgcolor="#FF8080">relationship_type</td>
    <td bgcolor="#FF8080">variation_theme</td>
    <td bgcolor="#FF9900">color_name</td>
    <td bgcolor="#FF9900">color_map</td>
    <td bgcolor="#FF9900">size_name</td>
    <td bgcolor="#FF9900">size_map</td>
  </tr>';
  while($row=mysql_fetch_array($result)){
    $key1="";
	$key2="";
	$key3="";
	$key4="";
	$key5="";
	$img1="";
	$img2="";
	$img3="";
	$img4="";
	$img5="";
	$img6="";
	$img7="";
	$img8="";
	$img9="";
	if(!empty($row[keywords])){
	$key=explode("\r\n",$row[keywords]);
	if(!empty($key[0])){$key1=$key[0];}
	if(!empty($key[1])){$key2=$key[1];}
	if(!empty($key[2])){$key3=$key[2];}
	if(!empty($key[3])){$key4=$key[3];}
	if(!empty($key[4])){$key5=$key[4];}
	}
	if(!empty($row[des])){
	$des=explode("\r\n",$row[des]);
	if(!empty($des[0])){$des1=$des[0];}
	if(!empty($des[1])){$des2=$des[1];}
	if(!empty($des[2])){$des3=$des[2];}
	if(!empty($des[3])){$des4=$des[3];}
	if(!empty($des[4])){$des5=$des[4];}
	}
	$sqla="select * from ph_img where proid='".$row[ID]."' and btid is null order by px asc";
	$resulta=mysql_query($sqla);
	while($rowa=mysql_fetch_array($resulta)){
	if(!empty($rowa[imgpath])){$img1="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img1="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img2="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img2="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img3="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img3="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img4="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img4="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img5="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img5="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img6="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img6="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img7="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img7="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img8="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img8="";}
	$rowa=mysql_fetch_array($resulta);
	if(!empty($rowa[imgpath])){$img9="http://".$_SERVER['SERVER_NAME']."/products/".$rowa[imgpath];}else{$img9="";}
	}
	$rowa=null;
	unset($rowa);
	$content=str_replace("\r\n",htmlentities('<br/>'),$row[content]);
	$content=htmlentities($content);
	$sqls="select * from ph_shuxing where proid='".$row[ID]."' order by ID asc";
  $results=mysql_query($sqls);
  if(mysql_num_rows($results)<1){$upc="UPC";$sku=$row[skucode];$parent="";}else{$upc="";$sku="";$parent="parent";}
  $tablebody.='<tr height="21">
    <td height="21">'.$row[code].'</td>
    <td>'.$sku.'</td>
    <td>'.$upc.'</td>
    <td>'.$row[proname].'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$content.'</td>
    <td>HOME</td>
    <td>Update</td>
    <td>'.$row[saleprice].'</td>
    <td>'.$row[coin].'</td>
    <td>'.$row[kucun].'</td>
    <td>New</td>
    <td></td>
    <td>'.$row[weight].'</td>
    <td>KG</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$des1.'</td>
    <td>'.$des2.'</td>
    <td>'.$des3.'</td>
    <td>'.$des4.'</td>
    <td>'.$des5.'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$key1.'</td>
    <td>'.$key2.'</td>
    <td>'.$key3.'</td>
    <td>'.$key4.'</td>
    <td>'.$key5.'</td>
    <td>'.$img1.'</td>
	<td>&nbsp;</td>
    <td>'.$img2.'</td>
    <td>'.$img3.'</td>
    <td>'.$img4.'</td>
    <td>'.$img5.'</td>
    <td>'.$img6.'</td>
    <td>'.$img7.'</td>
    <td>'.$img8.'</td>
    <td>'.$img9.'</td>
    <td>'.$parent.'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$row[btname].'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>';  
  while($rows=mysql_fetch_array($results)){
  $btimg1="";
  $btimg2="";
  $btimg3="";
  $btimg4="";
  $btimg5="";
  $btimg6="";
  $btimg7="";
  $btimg8="";
  $btimg9="";
  if(strpos($rows[cname],",")!==false){$cname=explode(",",$rows[cname]);$cname1=$cname[0];$cname2=$cname[1];}else{$cname1=$rows[cname];$cname2="";}
  $sqlb="select * from ph_img where btid='".$rows[ID]."'";
	$resultb=mysql_query($sqlb);
	while($rowb=mysql_fetch_array($resultb)){

	if(!empty($rowb[imgpath])){$btimg1="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}else{$btimg1=$img1;}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg2="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg3="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg4="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg5="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg6="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg7="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg8="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	$rowb=mysql_fetch_array($resultb);
	if(!empty($rowb[imgpath])){$btimg9="http://".$_SERVER['SERVER_NAME']."/products/".$rowb[imgpath];}
	}
  $tablebody.='<tr height="21">
    <td height="21">'.$row[code].'-'.$rows[cname].'</td>
    <td>'.$rows[skucode].'</td>
    <td>UPC</td>
    <td>'.$row[proname]."-".$rows[cname].'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$content.'</td>
    <td>HOME</td>
    <td>Update</td>
    <td>'.$rows[saleprice].'</td>
    <td>'.$row[coin].'</td>
    <td>'.$rows[kucun].'</td>
    <td>New</td>
    <td></td>
    <td>'.$row[weight].'</td>
    <td>KG</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$des1.'</td>
    <td>'.$des2.'</td>
    <td>'.$des3.'</td>
    <td>'.$des4.'</td>
    <td>'.$des5.'</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>'.$key1.'</td>
    <td>'.$key2.'</td>
    <td>'.$key3.'</td>
    <td>'.$key4.'</td>
    <td>'.$key5.'</td>
    <td>'.$btimg1.'</td>
	<td>&nbsp;</td>
    <td>'.$btimg2.'</td>
    <td>'.$btimg3.'</td>
    <td>'.$btimg4.'</td>
    <td>'.$btimg5.'</td>
    <td>'.$btimg6.'</td>
    <td>'.$btimg7.'</td>
    <td>'.$btimg8.'</td>
    <td>'.$btimg9.'</td>
    <td>child</td>
    <td>'.$row[code].'</td>
    <td>Variation</td>
    <td>'.$row[btname].'</td>
    <td>'.$cname1.'</td>
    <td>'.$cname1.'</td>
    <td>'.$cname2.'</td>
    <td>'.$cname2.'</td>
  </tr>';
  }
  }
  $tablefoot='</table>
</body>
</html>';
//echo $tablehead.$tablebody.$tablefoot;
export_xls($bname."-".date('Ymdhis', time()).".xls",$tablehead.$tablebody.$tablefoot);
}
?>
